package cn.cycleif.admin.controller;

import cn.cycleif.admin.service.AdminRoleService;
import cn.cycleif.app.service.RoleService;
import cn.cycleif.entity.Role;
import cn.cycleif.util.R;
import cn.dev33.satoken.annotation.SaCheckRole;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Date: 25/1/26-15:18
 * @Desc:
 */
@RestController
@RequestMapping("/sys/role")
@Tag(name = "角色管理", description = "禁用，授权等")
@SaCheckRole("admin")
public class AdminRoleController {

  @Autowired
  private AdminRoleService roleService;

  @PostMapping("/assign")
  @Operation(summary = "给用户分配角色")
  public R<String> role(Integer[] roleIds, Integer userId) {
    return roleService.assignRoles(roleIds, userId);
  }

  @PostMapping
  @Operation(summary = "添加角色")
  public R<String> add(String name , String remark) {
    return roleService.insert(name, remark);
  }

  @PutMapping
  @Operation(summary = "修改角色")
  public R<String> update(@RequestBody Role role) {
    return roleService.updateRole(role);
  }

  @GetMapping
  @Operation(summary = "获取角色列表")
  public R<List<Role>> list() {
    List<Role> list = roleService.list();
    return R.success(list);
  }

  @GetMapping("/{id}")
  @Operation(summary = "获取角色详情")
  public R<Object> detail(@PathVariable("id") Integer id) {
    return roleService.detail(id);
  }

}
